package com.bos.domain;

import org.springframework.security.core.GrantedAuthority;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: Latief
 * Date: 6/3/11
 * Time: 11:35 AM
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "role_")
public class Role implements GrantedAuthority, Serializable, DomainObject {
    @Id
    @Column(length = 20, name = "authority")
    @Size(max = 20, min = 1)
    private String authority;

/* --------------------------- Constructor ---------------------------*/

    public Role() {
    }

    public Role(String authority) {
        this.authority = authority;
    }


    public String getAuthority() {
        return authority;
    }

    public void setAuthority(String authority) {
        this.authority = authority;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Role)) return false;

        Role role = (Role) o;

        if (authority != null ? !authority.equals(role.authority) : role.authority != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return authority != null ? authority.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "Role{" +
                "authority='" + authority + '\'' +
                '}';
    }


/* -------------------------- Other Methods -------------------------- */

    public int compareTo(Object o) {
        return authority.compareTo((String) o);
    }
}
